<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>功能室申请-云校通</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
</head>
<body ontouchstart>
	<div class="weui_tab tab-bottom">
		<div class="weui_tab_bd">
			<div class="weui-header bg-blue"> 
				<div class="weui-header-left"> <a onclick="back()" class="icon icon-109 f-white">返回</a></div>
				<h1 class="weui-header-title">功能室申请</h1>
			</div>
	        <div class="weui_cells"style="margin: 0;">
				<div class="weui_cell">
					<div class="weui_cell_hd">
						<label class="weui_label">申请人</label>
					</div>
					<div class="weui_cell_bd weui_cell_primary">
						<p>${user.teacher.name }</p>
					</div>
				</div>
			</div>
	        
			<div class="weui_cells weui_cells_form">
				<div class="weui_cell weui_cell_select weui_select_after">
					<div class="weui_cell_hd">
						<label class="weui_label">部门</label>
					</div>
	                <div class="weui_cell_bd weui_cell_primary">
                		<select class="weui_select" id="depart" name="depart">
	                        <option value="">请选择</option>
	                    </select>
            		</div>
	            </div>
				<div class="weui_cell weui_cell_select weui_select_after">
					<div class="weui_cell_hd">
						<label class="weui_label">场室名称</label>
					</div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <select class="weui_select" id="roomName" name="roomName">
	                        <option value="">请选择</option>
	                    </select>
	                </div>
	            </div>
	            <div class="weui_cell">
					<div class="weui_cell_hd">
						<label class="weui_label">使用日期</label>
					</div>
	                <div class="weui_cell_bd weui_cell_primary">
                		<input id="useDate" name="useDate" type="text" class="weui_input" placeholder="请输入使用日期"/>
            		</div>
	            </div>
	            <div class="weui_cell">
					<div class="weui_cell_hd">
						<label class="weui_label">使用时段</label>
					</div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <input id="applyLesson" name="applyLesson" class="weui_input" placeholder="请输入使用时段"/>
	                </div>
	            </div>
	            <div class="weui_cell xtbg-add-list-title">
					<div class="weui_cell_bd weui_cell_primary">
						<p class="f14">使用原因和设备要求</p>
					</div>
				</div>
	            <div class="weui_cell">
	                <div class="weui_cell_bd weui_cell_primary">
	                    <textarea id="useReason" name="useReason" class="weui_textarea" placeholder="请输入使用原因" rows="3"></textarea>
	                </div>
	            </div>
	        </div>
	       <div class="weui_btn_area">
		        <a href="javascript:" onclick="submit()" class="weui_btn bg-blue">确认提交</a>
		    </div>
		</div>
	</div>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script src="<%=basePath %>/js/picker.js"></script>
<script src="<%=basePath %>/js/select.js"></script>
<script type="text/javascript">
	$(function() {
		initDepart();
		initFunctionRoom();
		$("#useDate").datetimePicker({title:"选择使用日期",min:getTime(new Date(), 'yyyy-MM-dd'),m:1});
		$("#applyLesson").select({
	        title: "选择使用时段",
	        multi: true,
	        split:',',
	        closeText:'完成',
	        items: [
	        	{title: "第1节",value: 1},
	        	{title: "第2节",value: 2},
	        	{title: "第3节",value: 3},
	        	{title: "第4节",value: 4},
	        	{title: "第5节",value: 5},
	        	{title: "第6节",value: 6},
	        	{title: "第7节",value: 7},
	        	{title: "第8节",value: 8},
	        	{title: "晚修一",value: 9},
	        	{title: "晚修二",value: 10}
	        ]
		});
	})
	function initDepart() {
		$.ajax({
			url: basePath + '/dictData/dictCode',
			type: 'post',
			dataType: 'json',
			data: {
				dictCode: "depart"
			},
			success: function(data) {
				if(data != null && data.length > 0) {
					var html = '';
					for(var i in data) {
						html += '<option value="'+data[i].dictDataValue+'">'+data[i].dictDataValue+'</option>';
					}
					$("#depart").append(html);
				}
			},
            error: function(xhr, type){
            	$.toptips("系统异常");
            }
		});
	}
	function initFunctionRoom() {
		$.ajax({
			url: basePath + '/dictData/dictCode',
			type: 'post',
			dataType: 'json',
			data: {
				dictCode: "function_room"
			},
			success: function(data) {
				if(data != null && data.length > 0) {
					var html = '';
					for(var i in data) {
						html += '<option value="'+data[i].dictDataValue+'">'+data[i].dictDataValue+'</option>';
					}
					$("#roomName").append(html);
				}
			},
            error: function(xhr, type){
            	$.toptips("系统异常");
            }
		});
	}
	function submit() {
		var depart = $("#depart").val();
		if(depart.length == 0) {
			$.alert("请选择所在部门!","");
			return;
		}
		var roomName = $("#roomName").val();
		if(roomName.length == 0) {
			$.alert("请选择功能室!","");
			return;
		}
		var useDate = $("#useDate").val();
		if(useDate.length == 0) {
			$.alert("请选择使用日期!","");
			return;
		}
		var applyLesson = $("#applyLesson").attr("data-values");
		if(!applyLesson) {
			$.alert("请选择申请时段!","");
			return;
		}
		var useReason = $("#useReason").val();
		if(useReason.length == 0) {
			$.alert("请输入使用原因!","");
			return;
		}
		$.ajax({
			url: basePath + '/ls/function/room/apply/submit',
			type: 'post',
			dataType: 'json',
			data: {
				depart: depart,
				roomName: roomName,
				useDateStr: useDate,
				applyLesson: applyLesson,
				useReason: useReason
			},
			success: function(data) {
				if (data.code == '000') {
					$.toast("提交成功！");
					setTimeout(function() {
	   					back();
	   				}, 1000);
				} else {
					$.toptips(data.msg);
				}
			},
            error: function(xhr, type){
            	$.toptips("系统异常");
            }
		});
	}
	
</script>
</body>
</html>